﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Glorysoft.EAP.EAPClient.Common;
using Microsoft.Practices.ServiceLocation;

namespace Glorysoft.EAP.EAPClient.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ViewModelLocator
    {
        static ViewModelLocator()
        {
            try
            {
                ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
                if (ViewModelBase.IsInDesignModeStatic)
                {
                    SimpleIoc.Default.Register<IDataService, DesignDataService>();
                }
                else
                {
                    SimpleIoc.Default.Register<IDataService, DataService>();
                }
                //global
                SimpleIoc.Default.Register<GlobalData>();
                //ViewModel
                SimpleIoc.Default.Register<LoginViewModel>();
                SimpleIoc.Default.Register<LogWindowViewModel>();
                SimpleIoc.Default.Register<MainViewModel>();
            }
            catch (System.Exception )
            {
            }
        }
        public GlobalData GlobalData
        {
            get { return ServiceLocator.Current.GetInstance<GlobalData>(); }
        }
        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Equip 
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }
        public LoginViewModel Login
        {
            get
            {
                return ServiceLocator.Current.GetInstance<LoginViewModel>();
            }
        }
        public LogWindowViewModel LogWindow
        {
            get
            {
                return ServiceLocator.Current.GetInstance<LogWindowViewModel>();
            }
        }
        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public  static void Cleanup()
        {
            
        }
    }
}